import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './assets/css/styles.css'
import './assets/css/global.css'
import './assets/css/reset.css'
import elementUI from 'element-ui'

import 'element-ui/lib/theme-chalk/index.css'

Vue.use(elementUI)

import axios from 'axios'

Vue.prototype.$axios = axios

import urls from './plugins/urls'

Vue.prototype.$HRMSUrl = urls.HRMS
Vue.prototype.$HRMSImageUrl = urls.HRMSImage
import AFTableColumn from 'af-table-column'

Vue.use(AFTableColumn)

import * as echarts from 'echarts';
Vue.prototype.$echarts=echarts

//设置axios的请求拦截
axios.interceptors.request.use(config => {
    console.log("============请求拦截=============")
    //在请求头中 设置 token 向后台发送
    let token = sessionStorage.getItem("token");
    if (token) {
        //设置请求头
        config.headers["token"] = token;
    }
    return config;
})

//回应拦截器
axios.interceptors.response.use(config => {


    if (config.data.code === 201) {
        //转到登录界面
        vueApp.$router.push("/login");
        vueApp.$message({
            type: "error",
            message: config.data.msg,
            duration: 1000
        })

        //如果没有登录 ，不向下请求
        return false;
    }
    return config;
})


Vue.config.productionTip = false

let vueApp = new Vue({
    router,
    render: h => h(App)
}).$mount('#app')
